home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11182 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: isonews.bbn.hp.com!hpbblb!news
  2. From: Matthias Dittrich <matti>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help!  Initializing a C string
  5. Date: 22 Mar 1996 12:28:44 GMT
  6. Organization: Hewlett-Packard Co.
  7. Message-ID: <4iu6ds$c74@hpbblb.bbn.hp.com>
  8. References: <1996Mar18.095842.2435@condor>
  9. NNTP-Posting-Host: trabant.bbn.hp.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
  14. X-URL: news:1996Mar18.095842.2435@condor
  15.  
  16. mdipilla@condor.navsses.navy.mil wrote:
  17. >to whom is all C' knowing...
  18. >
  19. >    I have a string which is formulating by several lines from an input file.
  20. >The approach we hae taken is to do a strncpy of the first line and then
  21. >strncat of each additional line.
  22. >
  23. >    When the string is formed we need to null it out so we can read the next
  24. >string in.
  25. >
  26. >    The problem we are having is that if we set the string to "\0"
  27. >we 
  28. >
  29. >      1. Overwrite the first line (strcpy)
  30. >      2. However the 2nd, 3rd, 4th, etch lines of the string are concatenated
  31. >after the initial string that wwas written.
  32. >
  33. > how do you INIitialze the variable  of the string so it is clear and you
  34. >do not have this overwrite problem.
  35. >..
  36. If you are using strncpy to copy the first line, the string has no '\0' at
  37. the end. You can put it there using:
  38. str[n] = '\0';
  39.  
  40. Hope this was your problem,
  41. Matthias
  42.  
  43.